package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.pro.constant.I18nStringConstant;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 刷评分脚本的操作行为
 * @author chunyang.qin
 * @version v1.0
 * @date 2020/11/30 21:47
 * @since v1.0
 */
@Getter
public enum ScoreOperationTypeEnum {
    /**
     * 加
     */
    ADD(0,I18nStringConstant.SCORE_ADD,"scoreAdd"),
    /**
     * 减
     */
    SUBTRACT(1, I18nStringConstant.SCORE_SUBTRACT,"scoreSubtract"),
    UNKNOWN(404,"enum.xbbRefType.name.unknown","unknown"),
    ;
    private Integer code;
    private String name;
    private String alias;

    ScoreOperationTypeEnum(Integer code, String name, String alias) {
        this.code = code;
        this.name = name;
        this.alias = alias;
    }


    /**
     * 通过枚举 alias 获得枚举
     *
     * @param alias 枚举别名
     *
     * @return ScoreOperationTypeEnum
     */
    public static ScoreOperationTypeEnum getByAlias(String alias) {
        for (ScoreOperationTypeEnum cacheCode : values()) {
            if (cacheCode.getAlias().equals(alias)) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 通过枚举 code 获得枚举
     *
     * @param code 枚举Code
     *
     * @return ScoreOperationTypeEnum
     */
    public static ScoreOperationTypeEnum getByCode(Integer code) {
        for (ScoreOperationTypeEnum cacheCode : values()) {
            if (Objects.equals(code, cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }
    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    /**
     * 操作行为：去除 404
     * @return
     */
    public static List<ScoreOperationTypeEnum> listScoreOperationType(){
        return Arrays.asList(ADD,SUBTRACT);
    }
}
